
package HibernateLayer;

import POJOs.SSessionAllocation;
import POJOs.client;
import POJOs.salary;
import POJOs.worker;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.hibernate.Session;

/**
 *
 * @author fabiofurlan
 */
public class VDocumentServices extends VRelationBasicServices<worker, salary> {

    
    @Override
    protected Class<salary> getTypeClass() {
        return salary.class;
    }

    @Override
    protected Class<worker> getTypeClassr() {
        return worker.class;
    }

    public VDocumentServices(){  
    }

    public VDocumentServices(Session sBean){
        this.sessionBean=sBean;
    }

    public VDocumentServices(SSessionAllocation sAlloc){
        this.sessionAllocation=sAlloc;
        //In this code line we add this object to observable list of SSessionAllocation instance
        this.sessionAllocation.addObserver(this);
        this.sessionBean=sAlloc.session;
    }

    public List<salary> getAllSalaryForClient(client myClient) throws SessionExausedExcepion{

        List<worker> wlist=null;
        List<salary> resultList=new ArrayList<salary> ();
        List<salary> aux=null;

        Iterator<worker> wlistiterator=null;

        this.checkValidity();
        VWorkerServices wservice=new VWorkerServices(sessionBean);
        wlist=wservice.listForeign(myClient);
        wlistiterator=wlist.iterator();

        while (wlistiterator.hasNext()) {
            worker elem = wlistiterator.next();
            aux=this.listForeign(elem);
            if(aux!=null){
                resultList.addAll(aux);
            }
        }
        return resultList;
    }

}
